package com.example.stars_project_android.personalCenter;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.stars_project_android.R;

import java.io.InputStream;

/**
 * 关于星记界面
 */
public class About extends AppCompatActivity implements View.OnClickListener {

    private ImageView imageBack, imgLogo, img;   //  返回设置，logo，logo大图
    private TextView softwareDetail;  //软件声明
    private Dialog dialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_about);

        //获取控件对象
        setView();
        init();
        //小图的点击事件（弹出大图）
        imgLogo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.e("logo","点击了小图");
                dialog.show();
            }
        });
    }

    /**
     * logo大图的操作
     */
    private void init() {
        //展示在dialog上面的大图
        dialog = new Dialog(About.this,R.style.FullActivity);

        WindowManager.LayoutParams attributes = getWindow().getAttributes();
        attributes.width = WindowManager.LayoutParams.MATCH_PARENT;
        attributes.height = WindowManager.LayoutParams.MATCH_PARENT;
        dialog.getWindow().setAttributes(attributes);

        img = getImageView();
        dialog.setContentView(img);

        //大图的点击事件（点击让他消失）
        img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.e("logo","点击了大图");
                dialog.dismiss();
            }
        });

    }

    /**
     * 动态的ImageView
     * @return
     */
    private ImageView getImageView(){
        ImageView imageView = new ImageView(this);
        //宽高
        imageView.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        //imageView设置图片
        @SuppressLint("ResourceType") InputStream is = getResources().openRawResource(R.mipmap.logo);
        Drawable drawable = BitmapDrawable.createFromStream(is, null);
        imageView.setImageDrawable(drawable);
        return imageView;
    }

    /**
     * 获取控件对象
     */
    private void setView() {
        imageBack = findViewById(R.id.iv_about_back);
        imageBack.setOnClickListener(this);
        imgLogo = findViewById(R.id.logo);
        softwareDetail = findViewById(R.id.software_detail);
        softwareDetail.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.iv_about_back:
                //返回到设置页面
                Intent intent = new Intent(About.this,SetUp.class);
                startActivity(intent);
                break;
            case R.id.software_detail:
                //展示软件声明

                break;
            default:
                break;
        }
    }
}